local skel = fk.CreateSkill{
  name = "tea__dianjie",
}
Fk:loadTranslationTable{
  ["tea__dianjie"] = "点解",
  [":tea__dianjie"] = "每轮开始时，你选择一名其他角色，本轮第一／二／三张【杀】结算后，你卜算2／其卜算1／你卜算3。因此技能卜算时，"..
  "你与其均互相可见，且其可以使用其中一张牌，然后此技能本轮失效。",
  ["@@__DrawPileTop"] = "牌堆顶",
  ["@@__DrawPileBottom"] = "牌堆底",
  ["@@tea__dianjie-round"] = "点解",
  ["#tea__dianjie-choose"] = "点解：选择一名其他角色",
  ["#tea__dianjie-use"] = "点解：你可以使用其中一张牌",
}
---@type TrigSkelSpec<RoundFunc>
local dianjie = {
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and #player.room:getAlivePlayers() > 1
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(player),
      skill_name = skel.name,
      prompt = "#tea__dianjie-choose"
    })
    if #to == 1 then
      room:notifySkillInvoked(player, skel.name, "special", to)
      room:setPlayerMark(player, "@@tea__dianjie-round", 1)
      room:setPlayerMark(to[1], "@@tea__dianjie-round", 1)
    end
  end
}
---@type TrigSkelSpec<UseCardFunc>
local dianjie_trig = {
  mute = true,
  can_trigger  = function (self, event, target, player, data)
    if player:hasSkill(skel.name) and data.card and data.card.trueName == "slash" and player:getMark("@@tea__dianjie-round") > 0 and table.find(player.room:getOtherPlayers(player), function (p)
      return p:getMark("@@tea__dianjie-round") > 0
    end) then
      local room = player.room
      local round_event = room.logic:getCurrentEvent():findParent(GameEvent.Round, true)
      if not round_event then return end
      local slashs = 0
      room.logic:getEventsByRule(GameEvent.UseCard, 1, function(e)
        local use = e.data
        if use.card.trueName == "slash" then
          slashs = slashs + 1
        end
        return false
      end, round_event.id)
      if slashs > 0 and slashs < 4 then
        event:setCostData(self, slashs)
        return true
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local slashs = event:getCostData(self)    ---@type number
    room:notifySkillInvoked(player, skel.name, "special")
    player:broadcastSkillInvoke(skel.name, slashs)
    local tos = table.filter(room:getOtherPlayers(player), function (p)
      return p:getMark("@@tea__dianjie-round") > 0
    end)
    if #tos == 1 then
      local to = tos[1]
      local list = { {player, 2, to}, {to, 1, player}, {player, 3, to} }
      local num = list[slashs]
      local result = room:askToGuanxing(num[1], {
        cards = room:getNCards(num[2], "top"),
        skill_name = skel.name,
      })
      local cards = table.filter(result.top, function (id)
        return room:getCardArea(id) == Card.DrawPile
      end)
      table.insertTableIfNeed(cards, table.filter(result.bottom, function (id)
        return room:getCardArea(id) == Card.DrawPile
      end))
      if not num[3].dead and #cards > 0 then
        for _, id in ipairs(cards) do
          if table.contains(result.top, id) then
            room:setCardMark(Fk:getCardById(id), "@@__DrawPileTop", 1)
          else
            room:setCardMark(Fk:getCardById(id), "@@__DrawPileBottom", 1)
          end
        end
        local use = room:askToUseRealCard(player, {
          pattern = tostring(Exppattern{ id = cards }),
          prompt = "#tea__dianjie-use",
          skill_name = skel.name,
          extra_data = {
            expand_pile = cards,
          }
        })
        for _, id in ipairs(cards) do
          room:setCardMark(Fk:getCardById(id), "@@__DrawPileTop", 0)
          room:setCardMark(Fk:getCardById(id), "@@__DrawPileBottom", 0)
        end
        if use and not player.dead then
          room:invalidateSkill(player, skel.name, "-round")
        end
      end
    end
  end
}
skel:addEffect(fk.RoundStart, dianjie)
skel:addEffect(fk.CardUseFinished, dianjie_trig)
return skel